package com.goldcn.order.model;

import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Created by 1111 on 2016/11/22.
 */
public class OrderAndItem extends OrderInfo{
    private List<OrderItem> orderItemList;

    private  String prdNoStr;

    private  String goodsInfoStr;


    @Autowired
    RestTemplate restTemplate;

    public List<OrderItem> getOrderItemList() {
        return orderItemList;
    }

    public void setOrderItemList(List<OrderItem> orderItemList) {
        this.orderItemList = orderItemList;
    }

    /**
     * 拼接导出详情产品款号
     * formart;1001,1002
     * @return
     */
    public String getPrdNoStr() {
        StringBuilder sb=new StringBuilder();
        if (orderItemList.size()<1){
            return "";
        }else{
            for (OrderItem item:orderItemList){
                sb.append(","+item.getPrdNo());
            }
        }
        return sb.toString().substring(1);
    }

    public void setPrdNoStr(String prdNoStr) {
        this.prdNoStr = prdNoStr;
    }

    /**
     * 拼接导出详情产品信息
     * formart;丝绸之路珍藏礼盒(颜色:福字币+蓝宝石 *1),丝绸之路珍藏礼盒(颜色:熊猫币+橄榄石 *1)
     * @return
     */
    public String getGoodsInfoStr() {
        StringBuilder sb=new StringBuilder();
        if (orderItemList.size()<1){
            return "";
        }else{
            for (OrderItem item:orderItemList){
                sb.append(","+item.getGoodsName()+"("+getJsonStr(item.getGoodsSku())+" *"+item.getQty()+")");
            }
        }
        return sb.toString().substring(1);
    }

    public void setGoodsInfoStr(String goodsInfoStr) {
        this.goodsInfoStr = goodsInfoStr;
    }

    private String getJsonStr(String sku){
        if (null==sku || "".equals(sku))
            return "";
        JSONObject json=JSONObject.fromObject(sku);
        return json.get("name").toString();
    }


}
